﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="InvokeMethodTypeReference.cs" company="JDML Consulting Ltd.">
//   Copyright 2011 Photon Project - http://photon.codeplex.com
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Photon.Windows.Input
{
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using Collections;

    internal class InvokeMethodTypeReference
    {
        private readonly ReadOnlyCollection<InvokeMethodTypeReference> _genericArgumentTypes;

        private static readonly ReadOnlyCollection<InvokeMethodTypeReference> EmptyGenericArguments = new ReadOnlyCollection<InvokeMethodTypeReference>(
            EmptyArray<InvokeMethodTypeReference>.Instance);

        public InvokeMethodTypeReference(string typeName) : this(typeName, null)
        {
        }

        public InvokeMethodTypeReference(string typeName, 
            IEnumerable<InvokeMethodTypeReference> genericArguments)
        {
            TypeName = typeName;
            if (genericArguments == null)
            {
                _genericArgumentTypes = EmptyGenericArguments;
            }
            else
            {
                _genericArgumentTypes = new ReadOnlyCollection<InvokeMethodTypeReference>(
                    new List<InvokeMethodTypeReference>(genericArguments));
            }
        }

        public string TypeName { get; set; }

        public ReadOnlyCollection<InvokeMethodTypeReference> GenericArgumentTypes
        {
            get { return this._genericArgumentTypes; }
        }

        public bool IsNullable
        {
            get { return TypeName[TypeName.Length - 1] == '?'; }
        }

        public bool IsGenericType
        {
            get { return GenericArgumentTypes.Count > 0; }
        }
    }
}